
// import searchBar from '../../components/searchbar/searchbar.js'
const util = require('../../utils/util.js');
const api = require('../../config/api.js');
import { getPageList } from '../../utils/paging'

let config = {
  data: {
    report: {
      page: 0,  //页码
      list: [],
      limit: 15,  //每页的数量
      PageCount: null,
      status: null,
      //判断显示image
      imageShow: true
    },

  },
  onLoad() {
    // searchBar();
    this.getPageList();
    console.log(this.data.report.list.length);
      this.setData({
        imageShow: this.data.report.list.length
      })
  },
  onReachBottom() {
    //判断当前是否加载下一页
    // console.log('PageCount:',this.data.report.PageCount);
    // console.log('page:',this.data.report.page);
    if (this.data.report.page < this.data.report.PageCount) {
      this.getPageList();
      console.log('加载下一页');
    } else {
      wx.showToast({
        title: '没有下一页数据了',
        icon: 'none',
        duration: 1000
      })
    }
  },
  //跳转
  goProjectApply() {
    wx.navigateTo({
      url: '/pages/projectEdit/projectEdit'
    })
  },
  //跳转到详情
  goProjectDetail(e) {
    console.log(e);
    const id = e.currentTarget.dataset.id;
    const orderNumber = e.currentTarget.dataset.ordernumber
    wx.navigateTo({
      url: '/pages/project_detail/project_detail?id=' + id + '&orderNumber=' + orderNumber
    })
  },
  //跳转到搜索页面
  searchClick() {
    wx.navigateTo({
      url: '/pages/search/search'
    })
  },
  //获取项目列表
  getPageList() {
    // let that = this
    const page = this.data.report.page + 1;
    getPageList(api.project_list, page, this.data.report.limit, 'get').then(res => {
      this.setData({
        //小程序不支持a.b的这种赋值 
        ['report.list']: [...this.data.report.list, ...res.data.list],
        ['report.PageCount']: Math.ceil(res.data.count / this.data.report.limit),
      })
      this.data.report.page += 1;
      for(let i=0;i<res.data.list.length;i++) {
        
        switch (res.data.list[i].orderNumber) {
          case 1:
            this.setData({
              [`report.list[${i}].orderNumber`]: '待受理',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 2:
            this.setData({
              [`report.list[${i}].orderNumber`]: '已受理',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 3:
            this.setData({
              [`report.list[${i}].orderNumber`]: '现地勘察',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 4:
            this.setData({
              [`report.list[${i}].orderNumber`]: '设计测算',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 5:
            this.setData({
              [`report.list[${i}].orderNumber`]: '已受图纸和资质审核',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 6:
            this.setData({
              [`report.list[${i}].orderNumber`]: '核准商定',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 7:
            this.setData({
              [`report.list[${i}].orderNumber`]: '呈报签约',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 8:
            this.setData({
              [`report.list[${i}].orderNumber`]: '施工割接',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 9:
            this.setData({
              [`report.list[${i}].orderNumber`]: '项目完成',
              [`report.list[${i}].orderColor`]: 'wancheng',
              orderColor: 'wancheng'
            })
            break;
          case 10:
            this.setData({
              [`report.list[${i}].orderNumber`]: '驳回',
              [`report.list[${i}].orderColor`]: 'duohui',
              orderColor: 'duohui'
            })
            break;
  
        }
        
      }
      // this.data.report.list.forEach((item,index) => {
      //   this.setData({
      //     [`report.list[${index}].orderNumber`]: orderNumber[index]
      //   })
      // })
      
    })
  }

}

Page(config);
